/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package menu;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Vector;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;

import model.Student;
import dao.StudentDao;
public class Son_menu {
	JFrame f ;
	JPanel p1 = new JPanel();	
	JPanel p2 = new JPanel();
	JButton b_add = new JButton("录入");
	JButton b_delet = new JButton("删除");
	JButton b_change = new JButton("修改");
	JButton b_find = new JButton("查找");
	JButton b_return = new JButton("返回");
	JTable t;
	DefaultTableModel  tableModel= null;
	public static void main(String args[]){
		new Son_menu().studentmenu();
	}
	
	//学生信息菜单
	public void studentmenu(){
		f = new JFrame("学生信息");
		ArrayList scan = new ArrayList();
		Vector columnNames = new Vector();
		columnNames.add("学号");
		columnNames.add("姓名");
		columnNames.add("性别");
		columnNames.add("出生年月");
		columnNames.add("学院代码");
		columnNames.add("所在班级");
		tableModel = new DefaultTableModel(columnNames,0);
		tableModel.addRow(columnNames);
		StudentDao ddao = new StudentDao();
		scan = ddao.findAll();
		for(int i=0;i<scan.size();i++){
			Vector v = new Vector(); 
			Student student = (Student)scan.get(i);
			v.add(student.getId());
			v.add(student.getName());
			v.add(student.getSex());
			v.add(student.getBorn_date());
			v.add(student.getDepart_id());
			v.add(student.getClass_name());
			tableModel.addRow(v);
		}
		t = new JTable(tableModel);
		t.setVisible(true);
		f.setLayout(new BorderLayout());
		f.add(p1,BorderLayout.NORTH);
		f.add(p2,BorderLayout.SOUTH);
		f.setBounds(400,200,600,400);
		p1.add(t);
		b_add.setActionCommand("学生录入");
		b_delet.setActionCommand("学生删除");
		b_change.setActionCommand("学生修改");
		b_find.setActionCommand("学生查找");
		b_add.addActionListener(new Monitor2());
		b_delet.addActionListener(new Monitor2());
		b_change.addActionListener(new Monitor2());
		b_find.addActionListener(new Monitor2());
		b_return.addActionListener(new Monitor2());
		p2.add(b_add);
		p2.add(b_delet);
		p2.add(b_change);
		p2.add(b_find);
		p2.add(b_return);
		f.setVisible(true);
	}
	
	//院系信息菜单
	public void departmenu(){
		f = new JFrame("院系信息");
		t = new JTable(100,2);
		t.setVisible(true);
		f.setLayout(new BorderLayout());
		f.add(p1,BorderLayout.NORTH);
		f.add(p2,BorderLayout.SOUTH);
		f.setBounds(400,200,400,400);
		p1.add(t);
		b_add.setActionCommand("院系录入");
		b_delet.setActionCommand("院系删除");
		b_change.setActionCommand("院系修改");
		b_find.setActionCommand("院系查找");
		b_add.addActionListener(new Monitor2());
		b_delet.addActionListener(new Monitor2());
		b_change.addActionListener(new Monitor2());
		b_find.addActionListener(new Monitor2());
		b_return.addActionListener(new Monitor2());
		p2.add(b_add);
		p2.add(b_delet);
		p2.add(b_change);
		p2.add(b_find);
		p2.add(b_return);
		f.setVisible(true);
	}
	
	//课程信息菜单
	public void coursemenu(){
		f = new JFrame("课程信息");
		t = new JTable(100,2);
		t.setVisible(true);
		f.setLayout(new BorderLayout());
		f.add(p1,BorderLayout.NORTH);
		f.add(p2,BorderLayout.SOUTH);
		f.setBounds(400,200,400,400);
		p1.add(t);
		b_add.setActionCommand("课程录入");
		b_delet.setActionCommand("课程删除");
		b_change.setActionCommand("课程修改");
		b_find.setActionCommand("课程查找");
		b_add.addActionListener(new Monitor2());
		b_delet.addActionListener(new Monitor2());
		b_change.addActionListener(new Monitor2());
		b_find.addActionListener(new Monitor2());
		b_return.addActionListener(new Monitor2());
		p2.add(b_add);
		p2.add(b_delet);
		p2.add(b_change);
		p2.add(b_find);
		p2.add(b_return);
		f.setVisible(true);
	}
	
	//成绩信息菜单
	public void scoremenu(){
		f = new JFrame("成绩信息");
		t = new JTable(100,2);
		t.setVisible(true);
		f.setLayout(new BorderLayout());
		f.add(p1,BorderLayout.NORTH);
		f.add(p2,BorderLayout.SOUTH);
		f.setBounds(400,200,400,400);
		p1.add(t);
		b_add.setActionCommand("成绩录入");
		b_delet.setActionCommand("成绩删除");
		b_change.setActionCommand("成绩修改");
		b_find.setActionCommand("成绩查找");
		b_add.addActionListener(new Monitor2());
		b_delet.addActionListener(new Monitor2());
		b_change.addActionListener(new Monitor2());
		b_find.addActionListener(new Monitor2());
		b_return.addActionListener(new Monitor2());
		p2.add(b_add);
		p2.add(b_delet);
		p2.add(b_change);
		p2.add(b_find);
		p2.add(b_return);
		f.setVisible(true);
	}
	
	private class Monitor2 implements ActionListener{
    	public void actionPerformed(ActionEvent e) {
			if(e.getActionCommand().equals("返回")){
				f.setVisible(false); 
				new Menu();
				}
			if(e.getActionCommand().equals("学生录入")){
				f.setVisible(false); 
				new Add_Menu().student_add();
				}
			if(e.getActionCommand().equals("学生删除")){
			f.setVisible(false); 
			new Delet_Menu().student_delet();
			}
			if(e.getActionCommand().equals("学生修改")){
			f.setVisible(false); 
			new Change_Menu().student_change();
			}
			if(e.getActionCommand().equals("学生查找")){
			f.setVisible(false); 
			new Find_Menu().student_find();
			}
    	}
    	
	}
}
